# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=libyaml
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.2.5
pkgrel=1
pkgdesc="YAML 1.1 library (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url="https://yaml.org/"
license=("MIT")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-pkg-config")
options=('staticlibs' 'strip')
source=("${_realname}-${pkgver}.tar.gz::https://github.com/yaml/libyaml/archive/${pkgver}.tar.gz"
        "0001-Proper-mingw-YAML_DECLARE-definition.patch"
        "0002-libyaml-no-undefined.patch")
sha256sums=('fa240dbf262be053f3898006d502d514936c818e422afdcf33921c63bed9bf2e'
            '101a650418d0f52cd7402a72cafe71412fb51a7d703f0f557412110c5aa395e5'
            'abf0b4ff0b19a142aaa27e2815cd5418ce1c4d4bcab2066f5085dafe2b5cc96a')

prepare() {
  cd ${srcdir}/${_realname}-${pkgver}
  patch -Np1 -i "${srcdir}/0001-Proper-mingw-YAML_DECLARE-definition.patch"
  patch -Np1 -i "${srcdir}/0002-libyaml-no-undefined.patch"

  autoreconf -fiv
}

build() {
  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  mkdir -p ${srcdir}/build-${MINGW_CHOST} && cd ${srcdir}/build-${MINGW_CHOST}

  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST}

  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" install
}
